﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Web.Security;
using webapp4U.DAL;

namespace webapp4U.BOL
{
    public class User : BizObject
    {
       
        #region Member Variables

        private String _userID;

        private String _userName;

        private String _password;

        private String _firstName;

        private String _lastName;

        private String _gender;

        private String _birthDay;

        private String _address;

        private String _email;

        private String _phone;

        private String _mobile;

        private String _fax;

        private Int32 _provinceID;

        private Int32 _countryID;

        private String _postalCode;

        private String _company;

        private String _companyDescription;

        private String _employeesSize;

        private String _website;

        private String _imageUrl;

        private DateTime _addedDate;

        private String _addedBy;

        private Boolean _isActive;

	    #endregion


	    #region Public Properties

        public String UserID
        {
            get { return _userID; }
            set { _userID = value; }
        }

        public String UserName
        {
            get { return _userName; }
            set { _userName = value; }
        }

        public String Password
        {
            get { return _password; }
            set { _password = value; }
        }

        public String FirstName
        {
            get { return _firstName; }
            set { _firstName = value; }
        }

        public String LastName
        {
            get { return _lastName; }
            set { _lastName = value; }
        }

        public String Gender
        {
            get { return _gender; }
            set { _gender = value; }
        }

        public String BirthDay
        {
            get { return _birthDay; }
            set { _birthDay = value; }
        }

        public String Address
        {
            get { return _address; }
            set { _address = value; }
        }

        public String Email
        {
            get { return _email; }
            set { _email = value; }
        }

        public String Phone
        {
            get { return _phone; }
            set { _phone = value; }
        }

        public String Mobile
        {
            get { return _mobile; }
            set { _mobile = value; }
        }

        public String Fax
        {
            get { return _fax; }
            set { _fax = value; }
        }

        public Int32 ProvinceID
        {
            get { return _provinceID; }
            set { _provinceID = value; }
        }

        public Int32 CountryID
        {
            get { return _countryID; }
            set { _countryID = value; }
        }

        public String PostalCode
        {
            get { return _postalCode; }
            set { _postalCode = value; }
        }

        public String Company
        {
            get { return _company; }
            set { _company = value; }
        }

        public String CompanyDescription
        {
            get { return _companyDescription; }
            set { _companyDescription = value; }
        }

        public String EmployeesSize
        {
            get { return _employeesSize; }
            set { _employeesSize = value; }
        }

        public String Website
        {
            get { return _website; }
            set { _website = value; }
        }

        public String ImageUrl
        {
            get { return _imageUrl; }
            set { _imageUrl = value; }
        }

        public DateTime AddedDate
        {
            get { return _addedDate; }
            set { _addedDate = value; }
        }

        public String AddedBy
        {
            get { return _addedBy; }
            set { _addedBy = value; }
        }

        public Boolean IsActive
        {
            get { return _isActive; }
            set { _isActive = value; }
        }
        #endregion


        #region public static Methods

        public static List<User> Test(out int Total)
        {
            UserDAL db = new UserDAL();
            return db.Test(out Total);
        }



        public static Boolean UpdateNewsLetter(String Email, Boolean NewsLetter)
        {
             UserDAL db = new UserDAL();
             return db.UpdateNewsLetter(Email, NewsLetter);
        }
        

        public static string EncodePassword(string Password)
        {
            string Format = "MD5";
            return FormsAuthentication.HashPasswordForStoringInConfigFile(Password, Format);
        }

        public static Boolean CheckUserName(String UserName)
        {
            UserDAL db = new UserDAL();
            return db.CheckUserName(UserName);
        }

        /// <summary>
        /// Phan nay Search dung cho Admin
        /// </summary>
        public static List<User> AdminSearch(String Keyword, String RoleName)
        {
            // keyword = null và RoleName <> Null
            if (Keyword.Trim().Length <= 0)
                return GetUserByRole(RoleName);
            else
            {
                UserDAL db = new UserDAL();
                return db.AdminSearch(Keyword, RoleName);
            }
        }



        public static List<User> SearchJobSeekers(String Keyword)
        {
            UserDAL db = new UserDAL();
            return db.SearchJobSeekers(Keyword);
        }


        public static List<User> SearchDetailJobSeekers(String Keyword, int JobTypeID, int ExperienceLevelID, int EducationLevelID)
        {
            UserDAL db = new UserDAL();
            return db.SearchDetailJobSeekers(Keyword, JobTypeID, ExperienceLevelID, EducationLevelID);
        }


        // Update ImageUrl
        public static Boolean UpdateImageUrl(String ImageUrl, String UserID)
        {
            UserDAL db = new UserDAL();
            return db.UpdateImageUrl(ImageUrl, UserID);
        }

        //search
        public List<User> Search(String Keyword, String RoleName, String SearchBy)
        {
            UserDAL db = new UserDAL();
            if (Keyword.Length > 0 && RoleName.Length > 0 && SearchBy.Length > 0)
                return db.Search(Keyword, RoleName, SearchBy);
            return null;
        }

        // Get First Name
        public static String GetFirstNameByUserID(String UserID)
        {
            UserDAL db = new UserDAL();
            User obj = User.GetUserByID(UserID);
            return obj.FirstName;
        }


        // Get Last Name
        public static String GetLastNameByUserID(String UserID)
        {
            UserDAL db = new UserDAL();
            User obj = User.GetUserByID(UserID);
            return obj.LastName;
        }


        // Get Address
        public static String GetAddressByUserID(String UserID)
        {
            UserDAL db = new UserDAL();
            User obj = User.GetUserByID(UserID);
            return obj.Address;
        }


        public static String GetCompanyByUserID(String UserID)
        {
            try
            {
                UserDAL db = new UserDAL();
                User obj = User.GetUserByID(UserID);
                return obj.Company;
            }
            catch { return ""; }
        }



        public static String GetUserIDByUserName(String UserName)
        {
            UserDAL db = new UserDAL();
            return db.GetUserIDByUserName(UserName);
        }


        public static String GetUserNameByUserID(String UserID)
        {
            UserDAL db = new UserDAL();
            return db.GetUserNameByUserID(UserID);
        }


        public static Boolean Approved(String Email)
        {
            UserDAL db = new UserDAL();
            return db.Approved(Email);
        }


        //*****************************************************************************
        public static int Insert(User obj)
        {
            UserDAL db = new UserDAL();
            return db.Insert(obj);
        }

        public static bool Update(User obj)
        {
            UserDAL db = new UserDAL();
            return db.Update(obj);
        }

        public static bool Delete(String UserID)
        {
            UserDAL db = new UserDAL();
            return db.Delete(UserID);
        }

        public static User GetUserByID(String UserID)
        {
            UserDAL db = new UserDAL();
            return db.GetUserByID(UserID);
        }


        //Get All User
        public static List<User> GetAllUser()
        {
            UserDAL db = new UserDAL();
            return db.GetAllUser(1, MAXROWS);
        }


        //Get All User
        public static List<User> GetAllUser(int PageIndex, int PageSize)
        {
            UserDAL db = new UserDAL();
            return db.GetAllUser(PageIndex, PageSize);
        }

        // Get Count All records of Table  User
        public static int GetCountUser()
        {
            UserDAL db = new UserDAL();
            return db.GetCountUser();
        }


        public static String[] GetUsersInRole(string Role)
        {
            return Roles.GetUsersInRole(Role);
        }
   
        //Get User By Role
        public static List<User> GetUserByRole(String Role)
        {
            UserDAL db = new UserDAL();
            return db.GetUserByRole(Role);
        }
               

        #endregion

    }
}
